﻿using Autofac;
using System.Reflection;
using Module = Autofac.Module;



namespace Rabbit.API
{
    public class AutofacModuleRegister:Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<Rabbit.Domain.RbacContext>().AsSelf().InstancePerLifetimeScope();
            // 批量注册服务
            builder.RegisterAssemblyTypes(
                Assembly.Load("Rabbit.Service"),
                Assembly.Load("Rabbit.Contracts")
                )
                .Where(a => a.Name.EndsWith("Service")).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(
               Assembly.Load("Rabbit.Domain")
               )
               .Where(a => a.Name.EndsWith("Repository")).AsImplementedInterfaces();

           // builder.RegisterType<TokenService>();
        }
    }
}
